import {
  methods,
  request,
} from '@/utils/request';//设置自己的request路径

const actions = {
  getMethod: {
    name: 'getMethod',
    url: '/getMethod',//后端接口
  },
  postMethod: {
    name: 'postMethod',
    url: '/postMethod',
  }
};
const customRequest = (
  action: any,
  token: string = '',
  formdata: any = null,
) => {
  const options: any = {
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      Accept: 'application/json',
      Authorization: token ? localStorage.getItem("token") : '',
    }
  };
  let url = action.url;
  switch (action.name) {
    case actions.getMethod.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.postMethod.name:
      options['method'] = methods.post;
      options['body'] = JSON.stringify(formdata);
      break;
    default:
  }
  return request(url, options);
};

export function getMethod(token: any, formdata: any) {
  return customRequest(actions.getMethod, formdata);
}

export function postMethod(token: any, formdata: any) {
  return customRequest(actions.postMethod,formdata);
}
